<template>
    <a-form-model :label-col="{ span: 4 }" :wrapper-col="{ span: 12 }">
        <a-form-model-item label="类型">
            <a-tag color="blue">拉合闸</a-tag>
        </a-form-model-item>
        <a-form-model-item label="是否开启">
            <a-switch v-model="info.is_close"/>
        </a-form-model-item>

        <a-form-model-item label="是否确定">
            <a-button type="primary" @click="closeHandleSubmit">提交</a-button>
        </a-form-model-item>

        <a-divider />

        <a-form-model-item label="类型">
            <a-tag color="blue">保电</a-tag>
        </a-form-model-item>
        <a-form-model-item label="是否开启">
            <a-switch v-model="info.is_protect"/>
        </a-form-model-item>

        <a-form-model-item label="是否确定">
            <a-button type="primary" @click="protectHandleSubmit">提交</a-button>
        </a-form-model-item>
    </a-form-model>
</template>


<script>
export default {
    props:['params'],
    data() {
        return {
            info: {},
            form: {},
        };
    },
    methods: {
        closeHandleSubmit() {
            if (this.info.is_close == true) {
                this.form.is_close = 1;
            }else{
                this.form.is_close = 2;
            }
            this.$post(this.$api.estateControl, {type: 2, code: this.params.tableAddress,id: this.params.id,is_close: this.form.is_close}).then(res => {
                if (res.code == 200) {
                    this.$message.success(res.msg)
                } else {
                    this.$message.error(res.msg)
                }
            })
        },
        protectHandleSubmit () {
            if (this.info.is_protect == true) {
                this.form.is_protect = 1;
            }else{
                this.form.is_protect = 2;
            }

            this.$post(this.$api.estateControl, {type: 1, id: this.params.id, is_protect: this.form.is_protect}).then(res => {
                if (res.code == 200) {
                    this.$message.success(res.msg)
                } else {
                    this.$message.error(res.msg)
                }
            })
        },
        get_info() {
            this.$get(this.$api.estateControl + '/' + 125).then(res => {
                for(let k in res.data){
                    if (res.data[k] == 2) {
                        res.data[k] = 0;
                    }
                }
                this.info = res.data;
            })
        },
        // 获取列表
        onload() {
            this.get_info();
        },

    },
    created() {
        this.onload();
    },
};
</script>
